#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>

int main()
{
    int pid = fork();
    if(pid < 0){
        perror("fail to fork");
        return -1;
    }
    //父进程
    else if(pid > 0){
        while(1){
            printf("PID = %d\nPPID = %d\n",getpid(),getppid());
            printf("**************\n");
            sleep(1);
        }
    }
    //子进程
    else{

        printf("PID = %d\nPPID = %d\n",getpid(),getppid());
        printf("--------------\n");
        sleep(1);
    }
    return 0;
}
